var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    accounts: 0,
    canget: 0,
    money: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var totalmoney = parseFloat(app.globalData.totalMoney) + parseFloat(app.globalData.cangetMoney);
    totalmoney = app.keepTwoDecimalFull(totalmoney);
    this.setData({
      accounts: app.globalData.totalMoney,
      totalmoney: totalmoney
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return app.shareToIndex();
  },
  withdrawfun:function(){
    var money = parseFloat(this.data.money);
    if(money <= 0){
      return;
    }
    var params = {
      money: money
    }
    var url = '/api/User/withdrawals';
    app.request(url,params).then(this.widthdrawfunCallBack.bind(this));
  },
  widthdrawfunCallBack:function(res){
    console.log(res);
    if(res.status == 'ok'){
      var accounts = res.result;
      app.toast.success('提现成功').then(res => {
        console.log('success');
        this.setData({
          accounts: accounts
        });
      });
    }
    else{
      app.toast.error(res.msg).then(res => {
        console.log('asdas');
      });
    }
  },
  changeDb:function(e){
    this.setData({
      money: e.detail.value
    });
  }
})